public class Demo14 {
    public static Object obj1 = new Object();
    public static Object obj2 = new Object();
    public static Object obj3 = new Object();

    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(() -> {
            for (int i = 0; i <10 ; i++) {
                synchronized (obj2) {
                    try {
                        obj2.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                System.out.print("A");
                synchronized (obj1) {
                    obj1.notify();
                }
            }
        });

        Thread t2 = new Thread(() -> {
            for (int i = 0; i <10 ; i++) {
                synchronized (obj1) {
                    try {
                        obj1.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                System.out.print("B");
                synchronized (obj3) {
                    obj3.notify();
                }
            }
        });

        Thread t3 = new Thread(() -> {
            for (int i = 0; i <10 ; i++) {
                synchronized (obj3) {
                    try {
                        obj3.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                System.out.println("C");
                synchronized (obj2) {
                    obj2.notify();
                }
            }
        });

        t1.start();
        t2.start();
        t3.start();
        Thread.sleep(1000);
        synchronized (obj2) {
            obj2.notify();
        }

    }
}

